/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package PCR;

import components.BandShape;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JToolBar;

/**
 *
 * @author asmaa
 */
public class MainFrame extends javax.swing.JFrame {

    private Integer sampleSize;
    NewPCR pcr;
    BandShape selected;
    Integer[] sample16Position = {64, 246, 428, 610, 792, 975, 1156, 1338,
        1520, 1702, 1884, 2066, 2248, 2430, 2612, 2794};
    Integer[] sample8Position = {168, 457, 746, 1035, 1324, 1613, 1902, 2191};

    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();
        pcr = new NewPCR();

    }

    public void setSampleSize(int size) {
        sampleSize = size;
        Integer[] samples = new Integer[sampleSize];
        for (int i = 0; i < sampleSize; i++) {
            samples[i] = i + 1;
        }
        samplesComboBox.setModel(new DefaultComboBoxModel(samples));
    }

    /*
     * This Fuction used to return array containing pixels positions for 16
     * samples
     */
    public Integer[] get16Position() {
        return sample16Position;
    }

    public void getCurrentBandPosition(String string) {
        jLabel1.setText(string);
    }
    
    /*
     * This function used to return reference to positioning toolbar
     */
    public JToolBar getPositioningToolbar()
    {
        return positioningToolBar;
    }
    
    /*
     * This Fuction used to return array containing pixels positions for 8
     * samples
     */

    public Integer[] get8Position() {
        return sample8Position;
    }

    /*
     * This function used to return reference to PCR internal frame
     */
    public NewPCR getPCR() {

        return pcr;
    }

    /*
     * This function return marker position related to samples number
     */
    public int getMarkerPos() {
        if (sampleSize == 16) {
            return sample16Position[0];
        } else {
            return sample8Position[0];
        }
    }

    /*
     * This function used to get selected object on the panel to chage its
     * position as shown in toolbar
     */
    public void setSelectedShape(BandShape shape) {
        selected = shape;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        desktopPane = new javax.swing.JDesktopPane();
        positioningToolBar = new javax.swing.JToolBar();
        toolBoxPanel = new javax.swing.JPanel();
        samplesComboBox = new javax.swing.JComboBox();
        positionTextField = new javax.swing.JTextField();
        applyButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        newMenu = new javax.swing.JMenu();
        PCRMenuItem = new javax.swing.JMenuItem();
        sequencerMenuItem = new javax.swing.JMenuItem();
        mRNAMenuItem = new javax.swing.JMenuItem();
        openMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        saveAsMenuItem = new javax.swing.JMenuItem();
        printMenuItem = new javax.swing.JMenuItem();
        closeMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        editMenu = new javax.swing.JMenu();
        undoMenuItem = new javax.swing.JMenuItem();
        redoMenuItem = new javax.swing.JMenuItem();
        cutMenuItem = new javax.swing.JMenuItem();
        copyMenuItem = new javax.swing.JMenuItem();
        pasteMenuItem = new javax.swing.JMenuItem();
        deleteMenuItem = new javax.swing.JMenuItem();
        newShapeMenu = new javax.swing.JMenu();
        bandMenuItem = new javax.swing.JMenuItem();
        dimerMenuItem = new javax.swing.JMenuItem();
        smearMenuItem = new javax.swing.JMenuItem();
        viewMenu = new javax.swing.JMenu();
        toolbarMenu = new javax.swing.JMenu();
        shapesCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem();
        formatCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem();
        toolboxMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        contentMenuItem = new javax.swing.JMenuItem();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Vacsera");
        setResizable(false);

        positioningToolBar.setRollover(true);
        positioningToolBar.setVisible(false);

        samplesComboBox.setToolTipText("Select Sample");

        positionTextField.setToolTipText("Select position related to The Marker");

        applyButton.setText("Apply");
        applyButton.setToolTipText("Apply Changes");
        applyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                applyButtonActionPerformed(evt);
            }
        });

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText(" ");
        jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        javax.swing.GroupLayout toolBoxPanelLayout = new javax.swing.GroupLayout(toolBoxPanel);
        toolBoxPanel.setLayout(toolBoxPanelLayout);
        toolBoxPanelLayout.setHorizontalGroup(
            toolBoxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(toolBoxPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(samplesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(positionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(applyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 492, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        toolBoxPanelLayout.setVerticalGroup(
            toolBoxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(toolBoxPanelLayout.createSequentialGroup()
                .addGroup(toolBoxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(samplesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(positionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(applyButton)
                    .addComponent(jLabel1))
                .addGap(0, 0, Short.MAX_VALUE))
        );

        positioningToolBar.add(toolBoxPanel);

        positioningToolBar.setBounds(0, 0, 290, 31);
        desktopPane.add(positioningToolBar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        fileMenu.setMnemonic('f');
        fileMenu.setText("File");

        newMenu.setText("New");

        PCRMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        PCRMenuItem.setText("PCR");
        PCRMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PCRMenuItemActionPerformed(evt);
            }
        });
        newMenu.add(PCRMenuItem);

        sequencerMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        sequencerMenuItem.setText("Sequencer");
        sequencerMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sequencerMenuItemActionPerformed(evt);
            }
        });
        newMenu.add(sequencerMenuItem);

        mRNAMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        mRNAMenuItem.setText("mRNA");
        mRNAMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mRNAMenuItemActionPerformed(evt);
            }
        });
        newMenu.add(mRNAMenuItem);

        fileMenu.add(newMenu);

        openMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        openMenuItem.setMnemonic('o');
        openMenuItem.setText("Open");
        fileMenu.add(openMenuItem);

        saveMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        saveMenuItem.setMnemonic('s');
        saveMenuItem.setText("Save");
        fileMenu.add(saveMenuItem);

        saveAsMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        saveAsMenuItem.setMnemonic('a');
        saveAsMenuItem.setText("Save As ...");
        saveAsMenuItem.setDisplayedMnemonicIndex(5);
        fileMenu.add(saveAsMenuItem);

        printMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
        printMenuItem.setText("Print");
        printMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(printMenuItem);

        closeMenuItem.setText("Close");
        closeMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(closeMenuItem);

        exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        exitMenuItem.setMnemonic('x');
        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        editMenu.setMnemonic('e');
        editMenu.setText("Edit");

        undoMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Z, java.awt.event.InputEvent.CTRL_MASK));
        undoMenuItem.setText("Undo");
        editMenu.add(undoMenuItem);

        redoMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Y, java.awt.event.InputEvent.CTRL_MASK));
        redoMenuItem.setText("Redo");
        editMenu.add(redoMenuItem);

        cutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        cutMenuItem.setMnemonic('t');
        cutMenuItem.setText("Cut");
        editMenu.add(cutMenuItem);

        copyMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        copyMenuItem.setMnemonic('y');
        copyMenuItem.setText("Copy");
        editMenu.add(copyMenuItem);

        pasteMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
        pasteMenuItem.setMnemonic('p');
        pasteMenuItem.setText("Paste");
        editMenu.add(pasteMenuItem);

        deleteMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        deleteMenuItem.setMnemonic('d');
        deleteMenuItem.setText("Delete");
        editMenu.add(deleteMenuItem);

        newShapeMenu.setText("Add Shape");

        bandMenuItem.setText("Band");
        newShapeMenu.add(bandMenuItem);

        dimerMenuItem.setText("Dimer");
        newShapeMenu.add(dimerMenuItem);

        smearMenuItem.setText("Smear");
        newShapeMenu.add(smearMenuItem);

        editMenu.add(newShapeMenu);

        menuBar.add(editMenu);

        viewMenu.setMnemonic('V');
        viewMenu.setText("View");

        toolbarMenu.setText("Toolbars");

        shapesCheckBoxMenuItem.setText("Shapes");
        toolbarMenu.add(shapesCheckBoxMenuItem);

        formatCheckBoxMenuItem.setText("Format");
        toolbarMenu.add(formatCheckBoxMenuItem);

        viewMenu.add(toolbarMenu);

        toolboxMenuItem.setText("Toolbox");
        toolboxMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                toolboxMenuItemActionPerformed(evt);
            }
        });
        viewMenu.add(toolboxMenuItem);

        menuBar.add(viewMenu);

        helpMenu.setMnemonic('h');
        helpMenu.setText("Help");

        contentMenuItem.setMnemonic('c');
        contentMenuItem.setText("Contents");
        helpMenu.add(contentMenuItem);

        aboutMenuItem.setMnemonic('a');
        aboutMenuItem.setText("About");
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(desktopPane, javax.swing.GroupLayout.PREFERRED_SIZE, 1057, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(desktopPane, javax.swing.GroupLayout.PREFERRED_SIZE, 657, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void printMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printMenuItemActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_printMenuItemActionPerformed

    private void PCRMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PCRMenuItemActionPerformed
        pcr.setVisible(true);
        pcr.toFront();
        desktopPane.add(pcr);
    }//GEN-LAST:event_PCRMenuItemActionPerformed

    private void closeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeMenuItemActionPerformed
    }//GEN-LAST:event_closeMenuItemActionPerformed

    private void sequencerMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sequencerMenuItemActionPerformed
        NewSequencer sec = new NewSequencer();
        sec.setVisible(true);
        sec.toFront();
        desktopPane.add(sec);
    }//GEN-LAST:event_sequencerMenuItemActionPerformed

    private void mRNAMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mRNAMenuItemActionPerformed
        NewmRNA mrna = new NewmRNA();
        mrna.setVisible(true);
        mrna.toFront();
        desktopPane.add(mrna);
    }//GEN-LAST:event_mRNAMenuItemActionPerformed

    private void toolboxMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_toolboxMenuItemActionPerformed
        Toolbox toolbox = new Toolbox();
        toolbox.setVisible(true);
        toolbox.setSize(200, 600);
        toolbox.setLocation(10, 40);
        toolbox.toFront();
        desktopPane.add(toolbox);
    }//GEN-LAST:event_toolboxMenuItemActionPerformed

    private void applyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyButtonActionPerformed
        // TODO add your handling code here:
        int sampleNu = (int) samplesComboBox.getSelectedItem();
        int y = Integer.parseInt(positionTextField.getText());
        int position;
        if(samplesComboBox.getItemCount() == 16)
        {
            position = sample16Position[sampleNu];
        }
        else
        {
            position = sample8Position[sampleNu];
        }
        selected.setLocation(position, y);
        pcr.getWorkArea().getBandsPanel().revalidate();
    }//GEN-LAST:event_applyButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem PCRMenuItem;
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JButton applyButton;
    private javax.swing.JMenuItem bandMenuItem;
    private javax.swing.JMenuItem closeMenuItem;
    private javax.swing.JMenuItem contentMenuItem;
    private javax.swing.JMenuItem copyMenuItem;
    private javax.swing.JMenuItem cutMenuItem;
    private javax.swing.JMenuItem deleteMenuItem;
    private javax.swing.JDesktopPane desktopPane;
    private javax.swing.JMenuItem dimerMenuItem;
    private javax.swing.JMenu editMenu;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JCheckBoxMenuItem formatCheckBoxMenuItem;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenuItem mRNAMenuItem;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenu newMenu;
    private javax.swing.JMenu newShapeMenu;
    private javax.swing.JMenuItem openMenuItem;
    private javax.swing.JMenuItem pasteMenuItem;
    private javax.swing.JTextField positionTextField;
    private javax.swing.JToolBar positioningToolBar;
    private javax.swing.JMenuItem printMenuItem;
    private javax.swing.JMenuItem redoMenuItem;
    private javax.swing.JComboBox samplesComboBox;
    private javax.swing.JMenuItem saveAsMenuItem;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JMenuItem sequencerMenuItem;
    private javax.swing.JCheckBoxMenuItem shapesCheckBoxMenuItem;
    private javax.swing.JMenuItem smearMenuItem;
    private javax.swing.JPanel toolBoxPanel;
    private javax.swing.JMenu toolbarMenu;
    private javax.swing.JMenuItem toolboxMenuItem;
    private javax.swing.JMenuItem undoMenuItem;
    private javax.swing.JMenu viewMenu;
    // End of variables declaration//GEN-END:variables
}
